#include <iostream>
#include <pthread.h>
using namespace std;

#define NUM 5
struct ThreadData
{
    ThreadData(int n):_n(n), _ret(0)
    {}
    int _n;
    int _ret;
};
void* Routine(void* args)
{
    ThreadData* td = static_cast<ThreadData*>(args);
    for(int i = 1; i <= td->_n; i++)
    {
        td->_ret += i;
    }
    pthread_exit((void*)td);
}
int main()
{
    pthread_t tids[NUM];
    for(int i = 0; i < NUM; i++)
    {
        ThreadData* td = new ThreadData(100 * i);
        pthread_create(tids + i, nullptr, Routine, (void*)td);
    }
    void* retval;
    for(int i = 0; i < NUM; i++)
    {
        pthread_join(tids[i], &retval);
        ThreadData* td = static_cast<ThreadData*>(retval);
        cout << "1->" << td->_n << ":计算结果" << td->_ret << endl;
    }
    return 0;
}